﻿using System;
using System.Collections.Generic;
using System.Text;
using CoderJoe.WoW.GearManager.Views;
using CoderJoe.WoW.Services;

namespace CoderJoe.WoW.GearManager
{
	public class LoadCharacterController
		: Controller
	{
		public LoadCharacterModel Model { get; private set; }
 
		public LoadCharacterController(Workspace workspace)
			: base(workspace)
		{
			Model = new LoadCharacterModel();
			RealmService realmService = Workspace.Resolve<RealmService>();
			Model.Realms = realmService.FindRealmsForRegion("US");
		}

		public void Show()
		{
			using (LoadCharacterDialog dialog = new LoadCharacterDialog(this))
			{
				if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
				{
					CharacterController controller = Workspace.Resolve<CharacterController>();
					controller.RefreshModel(Model.Realm, Model.Name);
				}
			}
		}

		public class LoadCharacterModel
			: Model
		{
			public string Name
			{
				get { return GetValue("Name", String.Empty); }
				set { SetValue("Name", value); }
			}

			public string Realm
			{
				get { return GetValue("Realm", String.Empty); }
				set { SetValue("Realm", value); }
			}

			public IEnumerable<string> Realms
			{
				get { return GetValue<IEnumerable<string>>("Realms", null); }
				set { SetValue("Realms", value); }
			}
		}
	}
}
